package com.nf.health.app.activity.miansearch.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.nf.health.app.R;
import com.nf.health.app.activity.miansearch.impl.SearchMainViewHolder;
import com.nf.health.app.inquiry.impl.bindviewhl.DocType;
import com.nf.health.app.inquiry.impl.viewholder.DoctorHeaderViewHolder;
import com.nf.health.app.models.SearchMainDocBean;
import com.nf.health.app.widget.OnMyOnClistener;

import java.util.List;

/**
 * Created by Jason on 2016/9/28.
 */
public class SearchMainRecyAdapter  extends RecyclerView.Adapter implements View.OnClickListener{
    private int CPOUNT_ITEM_NUM = 0;
    private LayoutInflater inflater;
    private Activity cnt ;
    private OnMyOnClistener onMyOnClistener;//注册点击事件

    public List<SearchMainDocBean> listSearchMainBean;

    public SearchMainRecyAdapter(Activity cnt,List<SearchMainDocBean> listSearchMainBean){
        inflater =LayoutInflater.from(cnt);
        this.cnt = cnt;
        this.listSearchMainBean = listSearchMainBean;
    }
    public void addDatas(List<SearchMainDocBean> datas){
        datas.addAll(datas);
        notifyDataSetChanged();
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        if(viewType == DocType.TYPE_SEARCH_DOC_LIST.getType()){
            View viewAds = inflater.inflate(R.layout.view_searchmain_doc, null);// 医生基本详情 头像，简介
            return new SearchMainViewHolder(viewAds,cnt);
//        }
//        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
//        if(holder instanceof SearchMainViewHolder){// ss搜索医生的评价
            SearchMainViewHolder searchMainViewHolder = (SearchMainViewHolder) holder;
            if(listSearchMainBean != null){
                searchMainViewHolder.loadData(listSearchMainBean.get(position));
            }
//        }
    }


    /**
     * 刷新功能
     * @param
     */
    public void setDoctorCommentData(List<SearchMainDocBean> listSearchMainBean){
        this.listSearchMainBean =listSearchMainBean;
        notifyItemInserted(getItemCount());//必须用此方法才能进行recycleview的刷新。（末尾刷新）
    }


    @Override
    public int getItemCount() {
        CPOUNT_ITEM_NUM = 0;
        if(listSearchMainBean != null){
            CPOUNT_ITEM_NUM = CPOUNT_ITEM_NUM + listSearchMainBean.size();
        }
        return CPOUNT_ITEM_NUM;
    }
    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return  DocType.TYPE_SEARCH_DOC_LIST.getType();
        }
        return  DocType.TYPE_SEARCH_DOC_LIST.getType();
    }
    @Override
    public void onClick(View v) {

    }


    public void regisitOnClickListener(OnMyOnClistener onMyOnClistener){
        this.onMyOnClistener = onMyOnClistener;
    }
}
